package com.gper.edu.vip.struct.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: ellis.guan
 * @Description: 媒婆
 * @Date: 2020/3/1 21:01
 * @Version: 1.0
 */
public class JDKMatchmaker implements InvocationHandler {
    private IPerson target;

    public JDKMatchmaker(IPerson target){
        this.target = target;
    }

    public Object getInstance(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("我是媒婆，开始为你物色对象");
        Object result = method.invoke(target,args);
        System.out.println("双方同意，可以开始交往");
        return result;
    }

}
